def scalar_product_test2(n,p):
    import random
    from psim import PSim
    
    ps = PSim(p)
    comm = ps.getComm()
    a = b = None
    if comm.rank==0:
        a = [random.random() for i in range(n)]
        b = [random.random() for i in range(n)]
    a = comm.one2all_scatter(0,a)
    b = comm.one2all_scatter(0,b)

    scalar = sum(a[i]*b[i] for i in range(len(a)))

    scalar = comm.all2one_reduce(0,scalar)
    if comm.rank == 0:
        print scalar

if __name__=='__main__': 
    scalar_product_test2(8,2)

